package com.goldgov.code.template.point.impl;

import com.goldgov.code.template.point.CodePoint;
import com.goldgov.code.utils.StringUtils;

public class MemberCodePoint extends CodePoint{

	private String modifier;
	
	private String[] annotation;
	
	private final String codes;

	public MemberCodePoint(String codes) {
		super("JAVA:MEMBER");
		this.codes = codes;
	}
	
	public MemberCodePoint(Class<?> clazz) {
		super("JAVA:MEMBER");
		this.codes = clazz.getName() + " " + StringUtils.lowerFirstChar(clazz.getSimpleName());
	}
	
	public MemberCodePoint(Class<?> clazz,String varName) {
		super("JAVA:MEMBER");
		this.codes = clazz.getName() + " " + varName;
	}
	
	@Override
	public String getCodes() {
		modifier = modifier == null ? "private" : modifier;
		StringBuilder strBuilder = new StringBuilder();
		if(annotation != null) {
			for (String anno : annotation) {
				strBuilder.append("    " + anno + "\r\n");
			}
		}
		strBuilder.append("    " + modifier + " " + codes + ";\r\n");
		return strBuilder.toString();
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	public void setAnnotation(String... annotation) {
		this.annotation = annotation;
	}
	
	public void setAnnotation(Class<?>... annoClass) {
		this.annotation = new String[annoClass.length];
		for (int i = 0; i < annoClass.length; i++) {
			this.annotation[i] = "@" + annoClass[i].getSimpleName();
		}
	}
	

}
